//进行打包  monerepo  获取需要打包的包
//获取 打包 目录
const fs = require("fs");
const execa = require('execa');
//注意只获取文件夹
const dir = fs.readdirSync("packages").filter(item=>{
  if(!fs.statSync(`packages/${item}`).isDirectory()){
    return false;
  }
  return true;
})
async function build(target){
  console.log(target);
  //注意exec -c 执行rollup配置，环境变量 -env
  await execa('rollup',['-c',"--environment",`TARGET:${target}`],{stdio:'inherit'})//子进程的输出在父包中输出
}

function runParaller(dir,itemfn){
  //遍历
  let result = [];
  for(let item of dir){
    result.push(itemfn(item));
  }
  return Promise.all(result);
}

//进行打包,并行打包
runParaller(dir,build).then(res=>{
  console.log("成功")
})
console.log(dir);